#!/bin/sh

echo "执行Flutter Build"

HOME_PATH=$(pwd)
EXPORT_ARCHIVE_PATH=$HOME_PATH/ios/archive
EXPORT_IPA_PATH=$HOME_PATH/ios/ipa

# 更新项目
echo "flutter pub upgrade"
flutter pub upgrade

# gradlew编译apk
cd android
echo "Build apk path: $HOME_PATH"
./gradlew build
echo "Build apk success."

# xcode-build 编译ipa
cd ..
cd ios

echo "EXPORT_ARCHIVE_PATH: $EXPORT_ARCHIVE_PATH"
echo "EXPORT_IPA_PATH: $EXPORT_IPA_PATH"

xcodebuild archive -workspace Runner.xcworkspace -scheme Runner -configuration Release -archivePath export/xcarchive/Runner.xcarchive -destination generic/platform=iOS
# xcodebuild archive -workspace Runner.xcworkspace -scheme Runner -configuration release -archivePath $EXPORT_ARCHIVE_PATH -exportPath $EXPORT_IPA_PATH CODE_SIGN_IDENTIFY=iPhone Distribution: Guangdong Jiahe Communication Technology Co., Ltd. PROVISIONING_PROFILE=1a73f4bc-fc29-496b-a0ea-3982328ee6bd
echo "Build .xcarchive success!"
